package com.ubaer.zsycz.inject.modules;


import android.app.Application;

import com.ubaer.zsycz.components.okhttp.LoggingInterceptor;
import com.ubaer.zsycz.views.MyCountDownTimer;

import java.util.concurrent.TimeUnit;

import javax.inject.Named;
import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;
import okhttp3.OkHttpClient;
import okhttp3.Request;

/**
 * author：lsw
 */
@Module
public class AppModule {
    private Application mApplication;

    public AppModule(Application mApplication) {
        this.mApplication = mApplication;
    }

    @Singleton
    @Provides
    public Application provideApplication() {
        return this.mApplication;
    }

    @Provides
    @Singleton
    public OkHttpClient provideOkHttpClient() {
        return new OkHttpClient.Builder()
                .connectTimeout(30, TimeUnit.SECONDS)
                .readTimeout(30, TimeUnit.SECONDS)
                .retryOnConnectionFailure(true)
                .addInterceptor(new LoggingInterceptor())
                .addNetworkInterceptor(chain -> {
                    Request request = chain.request();
                    return chain.proceed(request);
                })
                .build();
    }

    @Provides
    @Singleton
    @Named("default")
    public MyCountDownTimer provideMyCountDownTimer() {
        return new MyCountDownTimer(60000, 1000);
    }


}
